home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / human interface toolbox / progressbars / windows.c < prev   
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.5 KB  |  196 lines

  1. /*
  2.     File:        Windows.c
  3.  
  4.     Contains:    Handle application's windows    
  5.  
  6.     Written by: Chris White    
  7.  
  8.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/10/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24.  
  25.  
  26. #pragma segment Core
  27.  
  28. #include <Sound.h>
  29.  
  30. // System Includes
  31.  
  32. #ifndef __TYPES__
  33.     #include <Types.h>
  34. #endif
  35.  
  36. #ifndef __WINDOWS__
  37.     #include <Windows.h>
  38. #endif
  39.  
  40. #ifndef __QUICKDRAW__
  41.     #include <Quickdraw.h>
  42. #endif
  43.  
  44. #ifndef __RESOURCES__
  45.     #include <Resources.h>
  46. #endif
  47.  
  48. #ifndef __FONTS__
  49.     #include <Fonts.h>
  50. #endif
  51.  
  52. #ifndef __DIALOGS__
  53.     #include <Dialogs.h>
  54. #endif
  55.  
  56. #ifndef __ERRORS__
  57.     #include <Errors.h>
  58. #endif
  59.  
  60.  
  61.  
  62.  
  63. // Application Includes
  64.  
  65. #ifndef __BAREBONES__
  66.     #include "BareBones.h"
  67. #endif
  68.  
  69. #ifndef __PROTOTYPES__
  70.     #include "Prototypes.h"
  71. #endif
  72.  
  73.  
  74.  
  75.  
  76. // Static prototypes
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. void DoActivate ( EventRecord* theEvent )
  84. {
  85.     Boolean        bActiveFlag = theEvent->modifiers & resumeFlag;
  86.     SInt16        ignoreItem;
  87.     WindowRef    ignoreWindow;
  88.     WindowRef    theWindow = (WindowRef) theEvent->message;
  89.     GrafPtr        savePort;
  90.  
  91.     
  92.     GetPort ( &savePort );
  93.     SetPortWindowPort ( theWindow );
  94.     DialogSelect ( theEvent, &ignoreWindow, &ignoreItem );
  95.     SetPort ( savePort );
  96.     
  97.     return;
  98. }
  99.  
  100.  
  101.  
  102. void DoUpdate ( EventRecord* theEvent )
  103. {
  104.     OSErr            theErr;
  105.     GrafPtr            savePort;
  106.     CGrafPtr        thePort;
  107.     WindowRef        theWindow = (WindowRef) theEvent->message;
  108.     RgnHandle        theRgn;
  109.     
  110.     
  111.     
  112.     theRgn = NewRgn ( );
  113.     theErr = MemError ( );
  114.     if ( theErr )    goto CleanupAndBail;
  115.     
  116.     GetPort ( &savePort );
  117.     SetPortWindowPort ( theWindow );
  118.     BeginUpdate ( theWindow );                    // visRgn temporarily = updateRgn
  119.  
  120.     thePort = GetWindowPort ( theWindow );
  121.     UpdateDialog ( theWindow, thePort->visRgn );
  122.     DisposeRgn ( theRgn );
  123.     
  124.     EndUpdate ( theWindow );                    // restore normal visRgn of grafport
  125.     SetPort ( savePort );
  126.     
  127. CleanupAndBail:
  128.  
  129.     return;
  130. }
  131.  
  132.  
  133.  
  134. void DoContentClick ( WindowRef theWindow, EventRecord* theEvent )
  135. {
  136.     WindowRef    frontWindow;
  137.     
  138.     // If a movable modal is active, ignore click in an inactive 
  139.     // window, otherwise select it or handle the content click.
  140.     
  141.     frontWindow = FrontWindow ( );
  142.     if ( theWindow != frontWindow )
  143.     {
  144.         if ( IsMovableModal ( frontWindow ) )
  145.             SysBeep ( 30 );
  146.         else
  147.             SelectWindow ( theWindow );
  148.     }
  149.     else
  150.     {
  151.         SInt16        itemHit;
  152.         
  153.         if ( DialogSelect ( theEvent, &theWindow, &itemHit ) && itemHit == 1 )
  154.         {
  155.             tThreadedOperationPtr theInfo;
  156.             
  157.             theInfo = (tThreadedOperationPtr) GetWRefCon ( theWindow );
  158.             theInfo->bCancelled = true;
  159.         }
  160.     }
  161.     
  162.     return;
  163.     
  164. } // DoContentClick
  165.  
  166.  
  167.  
  168. void DoDragWindow ( WindowRef theWindow, EventRecord* theEvent )
  169. {
  170.     WindowRef    frontWindow;
  171.     
  172.     
  173.     // If a movable modal is active, ignore click in an inactive 
  174.     // title bar, otherwise let the Window Manager handle it.
  175.     
  176.     frontWindow = FrontWindow ( );
  177.     if ( theWindow != frontWindow && IsMovableModal ( frontWindow ) )
  178.         SysBeep ( 30 );
  179.     else                                
  180.     {
  181.         RgnHandle    theRgn;
  182.         Rect        dragRect;
  183.         
  184.         theRgn = GetGrayRgn ( );
  185.         dragRect = (*theRgn)->rgnBBox;
  186.         DragWindow ( theWindow, theEvent->where, &dragRect );
  187.     }
  188.     
  189.     return;
  190. }
  191.  
  192.  
  193.  
  194.  
  195.  
  196.